package top.heliming.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.heliming.interceptor.LoginInterceptor;

/**
 * description: //注册拦截器
 *
 * @author: heliming
 * @date:2019/05/22 上午 1:36
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

  /**
   * 通过@Bean注解，将我们定义的拦截器注册到Spring容器 * @return
   */
  @Bean
  public LoginInterceptor loginInterceptor() {
    return new LoginInterceptor();
  }
  /**
   * 重写接口中的addInterceptors方法，添加自定义拦截器
   * @param registry
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    // 通过registry来注册拦截器，通过addPathPatterns来添加拦截路径
    registry.addInterceptor(this.loginInterceptor()).addPathPatterns("/**");
  }
}